<%--
  Created by IntelliJ IDEA.
  User: 13585
  Date: 2020/12/23
  Time: 8:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="top.jsp"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>login</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/index.css" rel="stylesheet">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="js/jquery-3.2.1.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="js/bootstrap.min.js"></script>
    <style>
        /*#reg #msg{
            color: red;
            padding-left: 20px;
        }*/
    </style>
</head>
<body>
<div id="reg">

    <form class="form-horizontal" action="regUser" method="post" onsubmit="return checkReg()">
        <div class="form-group">
            <label for="inputName" class="col-sm-3 control-label">姓名:</label>
            <div class="col-sm-8">
                <input type="text" name="username" class="form-control" id="inputName" placeholder="请填写姓名">
            </div>
        </div>
        <span id="msg" class="col-sm-offset-3">手机号已被注册,请更换手机号</span>
        <div class="form-group">
            <label for="inputPhone" class="col-sm-3 control-label">手机号:</label>
            <div class="col-sm-8">
                <input type="number" name="phone" class="form-control" id="inputPhone" placeholder="请填写手机号">
            </div>
        </div>
        <div class="form-group">
            <label for="inputEmail" class="col-sm-3 control-label">电子邮箱:</label>
            <div class="col-sm-8">
                <input type="email" name="email" class="form-control" id="inputEmail" placeholder="请填写电子邮箱">
            </div>
        </div>
        <div class="form-group">
            <label for="inputPassword1" class="col-sm-3 control-label">密码:</label>
            <div class="col-sm-8">
                <input type="password" name="password" class="form-control" id="inputPassword1" placeholder="请填写密码">
            </div>
        </div>
        <div class="form-group">
            <label for="inputPassword2" class="col-sm-3 control-label">确认密码:</label>
            <div class="col-sm-8">
                <input type="password" class="form-control" id="inputPassword2" placeholder="请确认密码">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-10">
                <button id="sub" type="submit" class="btn btn-default">注册</button>
                <button type="reset" class="btn btn-default">清空</button>
            </div>
        </div>
    </form>
    <a class="login" href="#">有账号,去登录</a>
</div>
<script>
    let phone = document.getElementById("inputPhone");
    let ajax;
    phone.onblur = function () {
        if(window.XMLHttpRequest){
            ajax = new XMLHttpRequest();
        }else {
            ajax = new ActiveXObject("Microsoft.XMLHttp");
        }
        ajax.onreadystatechange = function () {
            if(ajax.readyState == 4 && ajax.status == 200){
                let span = document.getElementById("msg");
                let submit = document.getElementById("sub");
                let result = ajax.responseText;
                if(result == "t"){
                    span.style.display = "block";
                    submit.disabled = "disabled";
                }else{
                    span.style.display = "none";
                    submit.disabled = "";
                }
            }
        }
        ajax.open("post","formVerServlet");
        ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        ajax.send("phone="+this.value);
    }
</script>
<script>
    function checkReg() {
        let firstpassword = document.getElementById("inputPassword1").value;
        let lastpassword = document.getElementById("inputPassword2").value;
        if(firstpassword != lastpassword ){
            alert("两次密码不一样");
            return false;
        }
    }
</script>

</body>
</html>
